Next | Prev | Up | Top | Contents | Index

SCSI Utility Functions

The functions filldsreq(), fillg0cmd(), fillg1cmd(), ds_vtostr(), and ds_ctostr() are not oriented toward particular SCSI operations, but are used to construct your own task-oriented SCSI functions.


Using filldsreq()

The filldsreq() function is used to set the ds_flags, ds_databuf, and ds_datalen members of a dsreq structure. Its prototype is

void filldsreq(struct dsreq *dsp, uchar_t *data,long datalen, long flags)

The arguments are as follows:

dsp The address of a dsreq prepared by dsopen().
data The address of a buffer area.
datalen The length of the buffer area.
flags Flag values for ds_flags (see "Values for ds_flags").

The bits in flags are added to ds_flags with an OR; they do not replace the contents of the field.

Note: Besides the specified values, the function also sets 10000 in ds_timeout and clears ds_link, ds_synch, and ds_ret to zero.


Using fillg0cmd() and fillg1cmd()

The fillg0cmd() function stores a group 0 (6-byte) SCSI command in a command buffer. The fillg1cmd() stores a group 1 (10-byte) SCSI command in the buffer. Both functions set the ds_cmdbuf and ds_cmdlen fields of a dsreq. The function prototypes are:

void fillg0cmd(struct dsreq *dsp, uchar_t *cmdbuf, b0, ..., b5)
void fillg1cmd(struct dsreq *dsp, uchar_t *cmdbuf, b0, ..., b9)
The arguments are as follows:

dsp The address of any dsreq.
cmdbuf The address of a buffer to receive the command string.
b0, b1,...Expressions for the successive bytes of a SCSI command.

In typical use, the arguments are as follows:

dsp The address of a dsreq initialized by dsopen().
cmdbuf The command buffer allocated by dsopen(), whose address is stored in the ds_cmdbuf field of the dsreq.
b0 A SCSI command verb expressed as one of the constants declared in dslib.h, for example G0_INQU.

A typical call resembles the following:

fillg0cmd(dsp, (uchar_t *)CMDBUF(dsp), G0_INQU, 1, inq_page, 0, B1(datalen),0);

The macros B1(), B2(), and B4() defined in sys/dsreq.h are useful for expressing halfword and word values as byte sequences.


Using ds_vtostr() and ds_ctostr()

The dslib library module contains six static tables that can be used to convert between numeric values and character strings for message display. The tables are summarized in Table 5-8. The table definitions are in the source file dstab.c.

Lookup Tables in dslib
External NameTypeTable Contents
cmdnametabvtabNames for SCSI command bytes, for example "Test Unit."
cmdstatustabvtabNames for SCSI status byte codes, for example "BUSY."
dsrqnametabvtabDescriptions of flag values from ds_flags, for example "select with (without) atn" for DSRQ_SELATN.
dsrtnametabvtabDescriptions of return values in ds_ret, for example "parity error on SCSI bus" for DSRT_PARITY.
msgnametabvtabDescriptions of SCSI message bytes, for example "Save Pointers."
sensekeytabctabDescriptions of SCSI sense byte values, for example "Illegal Request."

The ds_vtostr() function searches any of the five vtab tables for the string matching an integer key. The ds_ctostr() function searches a ctab (currently, only sensekeytab is a ctab) for the string matching a key. The function prototypes are

char * ds_vtostr(unsigned long v, struct vtab *table);
char * ds_ctostr(unsigned long v, struct ctab *table);
Each function searches the specified table for a row containing the numeric value v, and returns address of the corresponding string. If there is no such row, the functions return the address of a zero-length string.


Next | Prev | Up | Top | Contents | Index